const moment=require('moment')
import {filter} from 'lodash'
  // 处理大数据，转换成B，M，K

export function formatBigNum(value, pos = '2'){
  value = Number(value)
  if (!value) {
    return value
  }

  if (value >= 1000000000000 || value <= -1000000000000) {
    return Number((value / 1000000000000).toFixed(pos)) + 'T'
  } else if (value >= 1000000000 || value <= -1000000000) {
    return Number((value / 1000000000).toFixed(pos)) + 'B'
  } else if (value >= 1000000 || value <= -1000000) {
    return Number((value / 1000000).toFixed(pos)) + 'M'
  } else if (value >= 1000 || value <= -1000) {
    return Number((value / 1000).toFixed(pos)) + 'K'
  }
  return Number(value.toFixed(pos))
}


/*
 * [{timestamp: '2020/9/1', locaedUSD: '2334234'}]
 */
export function formatOriginDefiData(datas) {
  let result = []
  datas.data.hits.map(item=>{
    var start = new Date('2018-01-01')
    var startTimes = start.getTime()
    if((item.timestamp * 1000) >= startTimes) {
       result.push([moment(item.timestamp * 1000).format('YYYY/MM/DD'), parseInt(item.lockedUsd)])
    }
  })
  return result.reverse();
}

export function formatOriginNews(datas) {
  return Object.values(datas).map(item => {
    return {
      title: item.title,
      day: moment(item.created_at).format('YYYY/MM/DD'),
      content: item.content,
      timestamp: moment(item.created_at).unix()
    }
  })
}


export function filterNews(news, day) {
  return filter(news, item => item.timestamp > moment(day).unix()).slice(0, 20)
}